package cn.com.nes.site.action.crm;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.crm.WorkbenchService;

@Controller("workbench")
@RequestMapping("/workbench")
public class WorkbenchAction {
	@Resource
	private WorkbenchService service;
	
	//获取数据概览
    @RequestMapping(method = RequestMethod.POST, value = "/getDataOverview")
    public @ResponseBody
    PageData getDataOverview(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getDataOverview(req) ;
        return res;
    }
    
    //获取客户状态
    @RequestMapping(method = RequestMethod.POST, value = "/getCustomerStatus")
    public @ResponseBody
    PageData getCustomerStatus(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getCustomerStatus(req) ;
        return res;
    }
    
    //获取我的待办
    @RequestMapping(method = RequestMethod.POST, value = "/getWillDeal")
    public @ResponseBody
    PageData getWillDeal(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getWillDeal(req) ;
        return res;
    }
    
    //获取我的待办
    @RequestMapping(method = RequestMethod.POST, value = "/getWillFollowUp")
    public @ResponseBody
    PageData getWillFollowUp(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getWillFollowUp(req) ;
        return res;
    }

    //获取线索转换
    @RequestMapping(method = RequestMethod.POST, value = "/getClueConversion")
    public @ResponseBody
    PageData getClueConversion(HttpServletRequest request,
                             HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getClueConversion(req) ;
        return res;
    }

    //获取排行榜
    @RequestMapping(method = RequestMethod.POST, value = "/getRankingList")
    public @ResponseBody
    PageData getRankingList(HttpServletRequest request,
                               HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getRankingList(req) ;
        return res;
    }

    // 保存日程
    @RequestMapping(method = RequestMethod.POST, value = "/saveSchedule")
    public @ResponseBody
    PageData saveSchedule(HttpServletRequest request,
                            HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveSchedule(req) ;
        return res;
    }

    // 查询日程
    @RequestMapping(method = RequestMethod.GET, value = "/getScheduleList")
    public @ResponseBody
    PageData getScheduleList(HttpServletRequest request,
                          HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getScheduleList(req) ;
        return res;
    }

    // 删除日程
    @RequestMapping(method = RequestMethod.POST, value = "/deletedSchedule")
    public @ResponseBody
    PageData deletedSchedule(HttpServletRequest request,
                             HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.deletedSchedule(req) ;
        return res;
    }

    // 查询关联业务
    @RequestMapping(method = RequestMethod.GET, value = "/getRelated")
    public @ResponseBody
    PageData getRelated(HttpServletRequest request,
                             HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getRelated(req) ;
        return res;
    }

}
